<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>产品明细</title>
</head>
<body>
<style type="text/css">
    .pro-img{
        border-radius: 3px;
        border: 1px solid #c4c4cd;
        padding: 3px;
    }
</style>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#pdg").datagrid({
            onLoadSuccess:function (data) {
                $("a[name='details']").linkbutton({
                    width:30,iconCls:'icon-my_detail',plain:true
                });
                $("a[name='delete-one-pro']").linkbutton({
                    onClick: function () {
                        var rowId = $(this).attr("id").substring(4);
                        $.messager.confirm("继续删除提示", "确定要删除选定的产品吗？", function (a) {
                            if (a) {
                                $.post("pros-del", {rowsId: rowId}, function (r) {
                                    if (r.success) {
                                        $.messager.alert("SUCCESS", "删除成功！", "info");
                                        $("#pdg").datagrid({
                                            url:'allProPaged',
                                            method:'post'
                                        });
                                        $("#pdg").datagrid("reload");
                                    } else {
                                        $.messager.alert("Failed", r.message, "error");
                                    }
                                });
                            }
                        });
                    },
                    width:30,iconCls:'icon-my_delete',plain:true
                });
                $("a[name='edit']").linkbutton({
                    width:30,iconCls:'icon-my_edit',plain:true
                });
                
            }
        });

        $("#reloadAllPro").linkbutton({
           onClick:function () {
               $("#pdg").datagrid({
                   url:'allProPaged',
                   method:'post'
               });
               $("#pdg").datagrid("reload");
           }
        });
        //删除选中的分类(批量删除)
        $("#pros-del-btn").linkbutton({onClick:function (){
                var rowsId = "";
                var rows = $("#pdg").datagrid('getSelections');
                if(rows.length>=1){
                    $.messager.confirm("继续删除提示","确定要删除选定的这些产品吗？",function (t) {
                        if(t){
                            for(var i =0; i<rows.length;i++){
                                if(i==0){
                                    rowsId=rowsId+rows[i].pid;
                                }else {
                                    rowsId=rowsId+","+rows[i].pid;
                                }

                            }
                            $.post("pros-del",{rowsId:rowsId},function (r) {
                                if(r.success){
                                    $.messager.alert("SUCCESS","删除成功！","info");
                                    $("#pdg").datagrid({
                                        url:'allProPaged',
                                        method:'post'
                                    });
                                    $("#pdg").datagrid("reload");
                                }else{
                                    $.messager.alert("Failed",r.message,"error");
                                }
                            });
                        }
                    });

                }else{
                    $.messager.alert("错误信息","未选中行！！！",'warning');
                }
            }});
        $("#pclist").menu({
            onShow:function () {
                $.ajax({
                    url:'maxdepth',
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        var item = $('#pclist').menu('findItem', '有分类');
                        $("#appendDiv").empty();
                        for(var i=1;i<=data;i++){
                            // 追加一个子菜单项
                            $('#pclist').menu('appendItem', {
                                parent: item.target,
                                text: '第'+i+'级分类',
                                id:'d'+i
                            });
                            $("#d"+i).attr("name","d"+i);
                            // $('<div>').addClass("menu-item").attr("name","d"+i).appendTo("#appendDiv");
                            // $('<div>'+i+'级分类</div>').addClass("menu-text").appendTo($("[name=d"+i+"]"));
                        }
                    }
                });
            }
        });
    });
    function format(value,row,index){
        var str='<a id = \"'+"pShow"+row.pid+'\" name="details" href="#" onclick="createDialogHut(\'detilsPro'+row.pid+'\',\'产品详情\',\'to-form-pro-details\','+row.pid+')" class="easyui-linkbutton edit-btn"></a>'+
            '<a id =\"'+"pDel"+row.pid+'\" name="delete-one-pro" href="#"  class="easyui-linkbutton edit-btn"></a>'+
            '<a id = \"'+"pUpdate"+row.pid+'\" name="edit" href="#" onclick="createDialogHut(\'editPro'+row.pid+'\',\'修改产品信息\',\'to-form-pro-update\','+row.pid+')" class="easyui-linkbutton edit-btn"></a>';
        return str;

    }
    function formatImg(value,row,index){
     // return '<div id="box">'+
     //        '<div class="small_pic">'+
     //        '<span class="slider"></span>'+
     //        '<a href="to-proImgZoomIn?value='+value+'\" target="_blank"><img  title=\"点击查看高清图\" alt=\"图片暂时无法显示\"  src=\"'+'productionsphotosZoomOut\\'+value+'\"/></a>'+
     //        '</div>'+
     //        '<div class="big_pic">'+
     //        '<img class="big_pic_img" src=\"'+'productionsphotosZoomOut\\'+value+'\"  width=\"150\" height=\"150\"/>'+
     //        '</div>'+
     //        '</div>';
        return '<a href="to-proImgZoomIn?value='+value+'\" target="_blank"><img  title=\"点击查看高清图\" alt=\"图片暂时无法显示\"  src=\"'+'productionsphotosZoomOut\\'+value+'\"/></a>';
    }
    function formatC(value,row,index) {
        if(value==""||value==null){
            return'<span style="font-size:12px;color:red;">暂无分类</span>';
        }else {
            return value;
        }
    }
    function formatM(value,row,index){
        if(value!=null){
            return '<b style="color:red;">'+'￥'+value+'</b>';
        }else{
            return value;
        }
    }

</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="pdg" class="easyui-datagrid table-chance" style="width: auto;" data-options="fit:true,striped:true,height:350,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-production',
pageList:[5,10,15,20],pageSize:10,url:'allProPaged',method:'post',scrollbarSize:0">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:5,align:'center',checkbox:true">编码</th>
                <th data-options="field:'pid',width:5,align:'center'">产品ID</th>
                <th data-options="field:'pname',width:10,align:'center'">产品名称</th>
                <th data-options="field:'pimg',width:10,align:'center'" formatter="formatImg">产品图片</th>
                <th data-options="field:'ptype',width:10,align:'center'">产品型号</th>
                <th data-options="field:'pspec',width:10,align:'center'">产品规格</th>
                <th data-options="field:'poprice',width:15,align:'center'" formatter="formatM">产品价格</th>
                <th data-options="field:'pcategory',width:10,align:'center',hidden:true">产品分类id</th>
                <th data-options="field:'pCategoryname',width:15,align:'center'" formatter="formatC">产品分类名</th>
                <th data-options="field:'pprice',width:15,align:'center'" formatter="formatM">产品成本价</th>
                <th data-options="field:'pbirthday',width:10,align:'center'">生产日期</th>
                <th data-options="field:'pouttime',width:10,align:'center'">失效日期</th>
                <th data-options="field:'pcompany',width:10,align:'center'">生产厂家</th>
                <th data-options="field:'pwunit',width:5,align:'center'">单位</th>
                <th data-options="field:'manager',width:20,align:'center'" formatter="format">操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-production" style="height:10%;">
            <a href="#" onclick="createDialog('newPro','新建商品','to-form-pro-add')" class="easyui-linkbutton" data-options="iconCls:'icon-mini_add2',plain:true">新建</a>
            <a href="#" id="pros-del-btn" class="easyui-linkbutton" data-options="iconCls:'icon-my_delete',plain:true">批量删除</a>
            <a  id="reloadAllPro" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>

            <input id="Pro-Search" class="easyui-searchbox" style="width: 35%;" data-options="searcher:function(value,name){
           $('#pdg').datagrid({
            url:'queryBypnameOrpidMh',
            method:'post',
            queryParams:{q:value,b:name}
            });
            $('#Pro-Search').searchbox('clear');
            $('#pdg').datagrid('reload');
           },prompt:'模糊查询产品名或产品id',menu:'#pclist'"/>
            <div id="pclist" class="easyui-menu" style="width:60px;">
                <div name="c1">所有内容</div>
                <div name="c2">无分类</div>
                <div>
                    <span>有分类</span>
                    <div id="appendDiv" style="width:70px;">
                    </div>
                </div>
            </div>
            <a href="#" onclick="createDialog('hlQueryPro','高级查询产品','to-form-pro-highLevel')" class="easyui-linkbutton">高级查询</a>
        </div>
    </div>
</div>
</body>
</html>

